package com.moresir.validatetools.rules.list.other;

import com.moresir.validatetools.impl.Form;
import com.moresir.validatetools.rules.list.AbstractRule;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;
import java.util.regex.Pattern;

/**
 * 有效的用户名
 */
public class RuleValidUserName extends AbstractRule {

    @Override
    public boolean isOkay(Form f) {
        Optional<String> s = f.getString(rule.getField());
        Pattern pattern = Pattern.compile("[0-9]+");
        boolean res = s.filter(str -> StringUtils.isBlank(str) || pattern.matcher(str).find()).isPresent();
        return ! res;
    }
}
